package com.piggy.im.service;

import cn.hutool.core.collection.CollUtil;
import com.piggy.im.domain.bo.SmsMessage;
import com.piggy.im.mq.model.SmsMsgMQ;
import com.piggy.mq.vender.IMQSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Slf4j
@Configuration
public class SmsMsgSend {

    private static IMQSender sender;

    @Resource
    public void setIMQSender(IMQSender mqSender) {
        sender = mqSender;
    }

    @Bean
    public SmsMsgSend stationMsgSend() {
        return new SmsMsgSend();
    }

    public static void send(SmsMessage payload) {
        if (CollUtil.isEmpty(payload.getPhoneNumbers())) {
            log.error("短信发送, 手机号码为空");
        }
        sender.send(new SmsMsgMQ(payload));
    }

}
